package com.geor.gcv.core.process;

import org.opencv.core.Mat;

/**
 * 虑色处理
 * 
 * @author geor.lusongnan, geor.yuli
 *
 */
public class ClearColorProcess extends Process {
	private Process process;
	static int offset = 15;

	public ClearColorProcess(Process process) {
		super();
		this.process = process;
	}

	@Override
	public Mat process() {
		Mat mat = process.process().clone();
		for (int j = 0; j < mat.cols(); j++) {
			for (int i = 0; i < mat.rows(); i++) {
				double[] matD = mat.get(i, j);
				if (checkRed(matD)) {
					mat.put(i, j, 250, 250, 250);
				}
			}
		}
		return mat;
	}

	@Override
	public String getProcessName() {
		return process.getProcessName() + "--> clear color process";
	}
	
	private boolean checkRed(double[] data) {
		if (data[2] > 160 && (data[2] - data[1] > offset || data[2] - data[0] > offset)) {
			return true;
		}
		return false;
	}

}
